package com.wang.rabbitmqstudy.config;

import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 交换机配置
 */
@Configuration
public class ExchangeConfig {
    @Autowired
    private PropertiesConfig propertiesConfig;

    @Bean
    DirectExchange studyDirectExchange() {
        return new DirectExchange(propertiesConfig.getDirectExchange(), true, false, null);
    }

    @Bean
    TopicExchange studyTopicExchange() {
        return new TopicExchange(propertiesConfig.getTopicExchange(), true, false, null);
    }

    @Bean
    FanoutExchange studyFanoutExchange() {
        return new FanoutExchange(propertiesConfig.getFanoutExchange(), true, false, null);
    }

    @Bean
    DirectExchange argumentsExchange() {
        return new DirectExchange(propertiesConfig.getArgumentsExchange(), true, false, null);
    }

    @Bean
    TopicExchange deadLetterExchange() {
        return new TopicExchange(propertiesConfig.getDeadLetterExchange(),true, false, null);
    }

    @Bean
    DirectExchange backupCommonExchange(){
        Map<String, Object> headers = new HashMap<>();
        headers.put("alternate-exchange", "backupExchange");
        return new DirectExchange(propertiesConfig.getBackupCommonExchange(), true, false, headers);
    }
    @Bean
    TopicExchange backupExchange(){
        return new TopicExchange(propertiesConfig.getBackupExchange(), true, false, null);
    }
}
